#!/bin/bash

# 组件复制脚本
# 使用方法: ./copy-to-project.sh /path/to/new-project

# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# 检查参数
if [ -z "$1" ]; then
    echo -e "${RED}错误: 请提供目标项目路径${NC}"
    echo "使用方法: ./copy-to-project.sh /path/to/new-project"
    exit 1
fi

TARGET_PROJECT="$1"
SOURCE_DIR="$(cd "$(dirname "$0")" && pwd)"

# 检查目标项目是否存在
if [ ! -d "$TARGET_PROJECT" ]; then
    echo -e "${RED}错误: 目标项目路径不存在: $TARGET_PROJECT${NC}"
    exit 1
fi

# 设置目标目录
TARGET_DIR="$TARGET_PROJECT/src/components/copy"

echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}开始复制组件到新项目${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e "源目录: ${YELLOW}$SOURCE_DIR${NC}"
echo -e "目标目录: ${YELLOW}$TARGET_DIR${NC}"
echo ""

# 创建目标目录
if [ ! -d "$TARGET_DIR" ]; then
    echo -e "${YELLOW}创建目标目录...${NC}"
    mkdir -p "$TARGET_DIR"
fi

# 复制文件
echo -e "${YELLOW}复制组件文件...${NC}"

# 复制 Vue 组件
cp "$SOURCE_DIR/RecommendView.vue" "$TARGET_DIR/" && echo "✅ RecommendView.vue"
cp "$SOURCE_DIR/ThreeLevelDirectory.vue" "$TARGET_DIR/" && echo "✅ ThreeLevelDirectory.vue"
cp "$SOURCE_DIR/ThreeLevelDirectoryExample.vue" "$TARGET_DIR/" && echo "✅ ThreeLevelDirectoryExample.vue"
cp "$SOURCE_DIR/tab.vue" "$TARGET_DIR/" && echo "✅ tab.vue"

# 复制 assets 目录
echo -e "${YELLOW}复制资源文件...${NC}"
if [ -d "$SOURCE_DIR/assets" ]; then
    cp -r "$SOURCE_DIR/assets" "$TARGET_DIR/" && echo "✅ assets/ (包含所有图片)"
else
    echo -e "${RED}⚠️  assets 目录不存在${NC}"
fi

# 复制文档
if [ -f "$SOURCE_DIR/README.md" ]; then
    cp "$SOURCE_DIR/README.md" "$TARGET_DIR/" && echo "✅ README.md"
fi

echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}复制完成！${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e "${YELLOW}接下来的步骤：${NC}"
echo "1. 检查新项目是否安装了必要的依赖："
echo "   - Taro 3.x"
echo "   - Vue 3"
echo "   - NutUI"
echo "   - UnoCSS"
echo ""
echo "2. 根据新项目结构调整导入路径："
echo "   - @/hooks"
echo "   - @/composables"
echo "   - @/service"
echo ""
echo "3. 配置接口地址和业务逻辑"
echo ""
echo "4. 查看 README.md 了解详细使用说明"
echo ""
echo -e "${GREEN}完成！祝开发顺利！${NC}"

